package com.seocoo.worker.base.menu;

import android.content.Context;
import android.graphics.Typeface;
import android.support.v4.app.Fragment;
import android.util.AttributeSet;
import android.widget.FrameLayout;
import android.widget.TextView;

import com.seocoo.worker.R;

/**
 * author : Ssp
 * date   : 2020/2/23 15:22
 * desc   : 文本tab切换
 */
public class NavigationTextButton extends FrameLayout {
    private Fragment mFragment = null;
    private Class<?> mClx;
    private TextView mTitleView;
    private String mTag;

    public NavigationTextButton(Context context) {
        super(context);
        init();
    }

    public NavigationTextButton(Context context, AttributeSet attrs) {
        super(context, attrs);
        init();
    }

    public NavigationTextButton(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        init();
    }


    private void init() {
        inflate(this.getContext(), R.layout.widget_layout_nav_text_item, this);
        mTitleView = findViewById(R.id.nav_tv_title);
    }

    @Override
    public void setSelected(boolean selected) {
        super.setSelected(selected);
        if (selected) {
            mTitleView.setTypeface(Typeface.defaultFromStyle(Typeface.BOLD));
        } else {
            mTitleView.setTypeface(Typeface.defaultFromStyle(Typeface.NORMAL));
        }
        mTitleView.setSelected(selected);
    }

    public void init(String text, Class<?> clx) {
        mTitleView.setText(text);
        mClx = clx;
        mTag = mClx.getName();
    }

    public Class<?> getClx() {
        return mClx;
    }

    public Fragment getFragment() {
        return mFragment;
    }

    public void setFragment(Fragment fragment) {
        this.mFragment = fragment;
    }

    @Override
    public String getTag() {
        return mTag;
    }
}
